package com.zzj.定时器;

import org.junit.Test;

import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author: zzj
 * @date: 2018/01/02
 * Time: 10:09
 */
public class TimerDemo {
    public void xixi(){
        System.out.println("aaa");
    }


    public static void main(String[] args) {
        ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1);
        TimerTask timerTask=new TimerTask() {
            @Override
            public void run() {
                System.out.println("b");
                new TimerDemo().xixi();
            }
        };
        newScheduledThreadPool.scheduleAtFixedRate(timerTask,0,2, TimeUnit.SECONDS);

    }
}

